-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(eviction): Tune eviction threshold in cache mode #4142
base: main
Are you sure you want to change the base?
fix(eviction): Tune eviction threshold in cache mode #4142
Conversation
cdd7fc0
to
b5e1611
Compare
5e6c873
to
2d7dd27
Compare
@adiholden I believe I've identified the issue: I'm calculating rss_threshold for each shard individually, but the current rss_memory value is a global metric for all shards |
9bd58cc
to
fe22e03
Compare
await asyncio.sleep(1) # Wait for RSS heartbeat update | ||
|
||
# First test that eviction is not triggered without connection creation | ||
stats_info = await async_client.info("stats") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets also add a check here that used memory is below maxmemory * 0.9 and rss curr memory is below
maxmemory * rss_oom_deny_ratio * 0.9
# Increase RSS memory by 30% of max memory | ||
# We can simulate RSS increase by creating new connections | ||
# Estimate memory per connection | ||
estimated_connection_memory = 15 * 1024 # 15 KB per connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this test supper stable and more controlled
I would run
CONFIG SET enable_heartbeat_eviction false
before creating the connections
after that check the rss make sure its above the threshold
then run
CONFIG SET enable_heartbeat_eviction true
and after that check that rss memory dropped below the threshold and check the stats for evicted keys as you did below
0097d0a
to
40d6063
Compare
fixes dragonflydb#4139 Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
Signed-off-by: Stepan Bagritsevich <[email protected]>
40d6063
to
692a3fa
Compare
Signed-off-by: Stepan Bagritsevich <[email protected]>
692a3fa
to
051412e
Compare
src/server/engine_shard.cc
Outdated
return max_memory - used_memory; | ||
} | ||
// negative value indicates memory overuse | ||
return -1 * ssize_t(used_memory - max_memory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect results if max_memory > used_memory because size_t - size_t = size_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ssize_t CalculateMemoryBudget(size_t max_memory, size_t used_memory) {
if (max_memory >= used_memory) {
return max_memory - used_memory;
}
// negative value indicates memory overuse
return -1 * ssize_t(used_memory - max_memory);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I got, the result is correct because you use overflow of ssize_t type, but it can be UB I'm not sure. please rewrite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to round size_t to max ssize_t? Because I already implemented this previously
#4142 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just update ssize_t CalculateMemoryBudget(ssize_t max_memory, ssize_t used_memory)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we are still converting size_t to ssize_t before calling the function. This is even more dangerous because we did not perform the subtraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, we are using this values
atomic_uint64_t used_mem_peak(0);
atomic_uint64_t used_mem_current(0);
atomic_uint64_t rss_mem_current(0);
atomic_uint64_t rss_mem_peak(0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in our case, such converting is absolutely safe, because we will never get such a memory size in the near future
Signed-off-by: Stepan Bagritsevich <[email protected]>
fixes #4139